package com.gomoku;

import java.io.*;
import java.util.*;

public class GameRecorder {
    private List<int[]> moveHistory;
    private String recordFile;

    public GameRecorder(String recordFile) {
        this.moveHistory = new ArrayList<>();
        this.recordFile = recordFile;
    }

    public void recordMove(int row, int col) {
        moveHistory.add(new int[]{row, col});
    }

    public void saveRecord() {
        try (PrintWriter writer = new PrintWriter(new FileWriter(recordFile))) {
            for (int[] move : moveHistory) {
                writer.println(move[0] + "," + move[1]);
            }
        } catch (IOException e) {
            System.err.println("保存游戏记录失败: " + e.getMessage());
        }
    }

    public List<int[]> getMoveHistory() {
        return new ArrayList<>(moveHistory);
    }

    public void clear() {
        moveHistory.clear();
    }
}